﻿namespace ufida.u9.ait.openapi
{
    using Newtonsoft.Json;
    using System;
	using System.Collections.Generic;
    using System.IO;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Json;
    using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.Base;
    using UFIDA.U9.CBO.Pub.Controller;
    using UFIDA.U9.CBO.SCM.Item;
    using UFIDA.U9.ISV.Item;
    using UFIDA.U9.ISV.Item.Proxy;
    using UFSoft.UBF.AopFrame;
    using UFSoft.UBF.Business;
    using UFSoft.UBF.Util.Context;

	/// <summary>
	/// ItemMasterCreateSV partial 
	/// </summary>	
	public partial class ItemMasterCreateSV 
	{	
		internal BaseStrategy Select()
		{
			return new ItemMasterCreateSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class ItemMasterCreateSVImpementStrategy : BaseStrategy
	{
		public ItemMasterCreateSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			ItemMasterCreateSV bpObj = (ItemMasterCreateSV)obj;

            try
            {
				if (bpObj.Data == null || bpObj.Data.Count==0)
					throw new Exception("传入参数为空");
				List<UFIDA.U9.CBO.SCM.Item.ItemMasterData> retlist=new List<ItemMasterData> ();

                List<object> inputdtos = DTOUtils.DTOListPropCopy(bpObj.Data.ConvertAll(item=>item as object)
					, typeof(UFIDA.U9.ISV.Item.ItemMasterDTOData));
				//foreach(UFIDA.U9.ISV.Item.ItemMasterDTOData dto in inputdtos)
    //            {
				//	ItemMaster item = ItemMaster.Finder.Find($"Code={dto.Code}");
    //                if (item == null)
    //                {
				//		//新增逻辑
				//		BatchCreateItemByDTOSRVProxy proxy = new BatchCreateItemByDTOSRVProxy();
				//		proxy.ItemMasterDTOs = new List<UFIDA.U9.ISV.Item.ItemMasterDTOData>() { dto };
				//		proxy.ContextDTO = U9Utils.createContext();
				//		List<UFIDA.U9.CBO.SCM.Item.ItemMasterData> ret = proxy.Do();
				//		if (ret.Count > 0)
				//			retlist.Add(ret[0]);
				//	}
    //                else
    //                {
				//		//修改逻辑
				//		BatchModifyItemByDTOSRVProxy proxy = new BatchModifyItemByDTOSRVProxy();
				//		proxy.ItemMasterDTOs = new List<UFIDA.U9.ISV.Item.ItemMasterDTOData> () { dto };
				//		proxy.ContextDTO = U9Utils.createContext();
				//		List<UFIDA.U9.CBO.SCM.Item.ItemMasterData> ret = proxy.Do();
				//		if (ret.Count > 0)
				//			retlist.Add(ret[0]);
				//	}
				//}
                return ResultUtils.success(inputdtos);
			}catch (Exception ex)
            {
				return ResultUtils.error(ex.Message,ex.StackTrace);
			}
		}		
	}

	#endregion
	
	
}